using Microsoft.AspNetCore.Mvc;
using JTZY.Model.Goods.Dto;
using JTZY.Model.Goods;
using JTZY.Service.Goods.IGoodsService;
using JTZY.Admin.WebApi.Filters;

//创建时间：2024-10-27
namespace JTZY.Admin.WebApi.Controllers.Goods
{
    /// <summary>
    /// 商品分类
    /// </summary>
    [Verify]
    [Route("goods/Corecmsgoodscategory")]
    public class CorecmsgoodscategoryController : BaseController
    {
        /// <summary>
        /// 商品分类接口
        /// </summary>
        private readonly ICorecmsgoodscategoryService _CorecmsgoodscategoryService;

        public CorecmsgoodscategoryController(ICorecmsgoodscategoryService CorecmsgoodscategoryService)
        {
            _CorecmsgoodscategoryService = CorecmsgoodscategoryService;
        }

        /// <summary>
        /// 查询商品分类列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "corecmsgoodscategory:list")]
        public IActionResult QueryCorecmsgoodscategory([FromQuery] CorecmsgoodscategoryQueryDto parm)
        {
            var response = _CorecmsgoodscategoryService.GetList(parm);
            return SUCCESS(response);
        }

        /// <summary>
        /// 查询商品分类列表树
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("treeList")]
        [ActionPermissionFilter(Permission = "corecmsgoodscategory:list")]
        public IActionResult QueryTreeCorecmsgoodscategory([FromQuery] CorecmsgoodscategoryQueryDto parm)
        {
            var response = _CorecmsgoodscategoryService.GetTreeList(parm);
            return SUCCESS(response);
        }

        /// <summary>
        /// 查询商品分类详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "corecmsgoodscategory:query")]
        public IActionResult GetCorecmsgoodscategory(int Id)
        {
            var response = _CorecmsgoodscategoryService.GetInfo(Id);
            
            var info = response.Adapt<CorecmsgoodscategoryDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加商品分类
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "corecmsgoodscategory:add")]
        [Log(Title = "商品分类", BusinessType = BusinessType.INSERT)]
        public IActionResult AddCorecmsgoodscategory([FromBody] CorecmsgoodscategoryDto parm)
        {
            var modal = parm.Adapt<Corecmsgoodscategory>().ToCreate(HttpContext);

            var response = _CorecmsgoodscategoryService.AddCorecmsgoodscategory(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新商品分类
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "corecmsgoodscategory:edit")]
        [Log(Title = "商品分类", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateCorecmsgoodscategory([FromBody] CorecmsgoodscategoryDto parm)
        {
            var modal = parm.Adapt<Corecmsgoodscategory>().ToUpdate(HttpContext);
            var response = _CorecmsgoodscategoryService.UpdateCorecmsgoodscategory(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除商品分类
        /// </summary>
        /// <returns></returns>
        [HttpPost("delete/{ids}")]
        [ActionPermissionFilter(Permission = "corecmsgoodscategory:delete")]
        [Log(Title = "商品分类", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteCorecmsgoodscategory([FromRoute]string ids)
        {
            var idArr = Tools.SplitAndConvert<int>(ids);

            return ToResponse(_CorecmsgoodscategoryService.Delete(idArr));
        }

    }
}